package com.yanqu.road.dataHelper.action.excel;

import com.yanqu.road.dataHelper.gameServer.GameServer;
import com.yanqu.road.dataHelper.manager.ConfigMgr;
import com.yanqu.road.dataHelper.manager.DataMgr;
import com.yanqu.road.dataHelper.repair.BaseRepair;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Author xx
 * @Date 2020/11/11
 */
public class GameRecharge extends BaseRepair {

    public GameRecharge(GameServer gameServer) {
        super(gameServer);
    }

    @Override
    public void repair(long param1, String param2) {

    }

    public void go(String startTime,String endTime){
        List<Map<String, String>> listMap = new ArrayList<>();
        listMap = getRechargeOrder(startTime,endTime);
        DataMgr.addData(listMap);
    }

    private List<Map<String, String>> getRechargeOrder(String start,String end) {
        List<Map<String, String>> dataList = new ArrayList<>();
        ResultSet rs = null;
        CallableStatement call = null;
        String sql = "select * " +
                " from t_u_recharge_detail " +
                " where (orderStatus = 1 OR orderStatus = 2) AND createTime > ? AND createTime < ?";
        try {
            call = getGameServer().getConnection().prepareCall(sql);
            int i=1;
            call.setString(i++,start);
            call.setString(i++,end);
            rs = call.executeQuery();
            while (rs.next()) {
                Map<String,String> temp = new ConcurrentHashMap<>();
                temp.put("serverId",String.valueOf(getGameServer().getServerInfo().getServerId()));
                temp.put("orderNo",checkNullToEmpty(rs.getString("orderNo")));
                temp.put("userId",checkNullToEmpty(rs.getString("userId")));
                temp.put("amount",checkNullToEmpty(rs.getString("amount")));
                temp.put("orderStatus",checkNullToEmpty(rs.getString("orderStatus")));
                temp.put("createTime",checkNullToEmpty(rs.getString("createTime")));
                temp.put("platformOrderNo",checkNullToEmpty(rs.getString("platformOrderNo")));
                temp.put("mallId",checkNullToEmpty(rs.getString("mallId")));
                temp.put("mallName", ConfigMgr.getMallName(Integer.valueOf(temp.get("mallId"))));
                dataList.add(temp);
            }
        } catch (SQLException ex) {
            getGameServer().getLogger().error("异常错误", ex);
        } finally {
            getGameServer().closeConnection(call, rs);
        }
        return dataList;
    }
}
